package com.gxcc3.ygps.web.controller.check;

import com.alibaba.fastjson2.JSONObject;
import com.gxcc3.ygps.common.core.controller.BaseController;
import com.gxcc3.ygps.common.core.domain.AjaxResult;
import com.gxcc3.ygps.common.core.domain.entity.SysCheckDetection;
import com.gxcc3.ygps.common.core.domain.entity.SysCheckDispose;
import com.gxcc3.ygps.common.core.page.TableDataInfo;
import com.gxcc3.ygps.system.service.ISysCheckDisposeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 检测管理 检测列表
 */
@RestController
@RequestMapping("/check/dispose")
public class SysCheckDisposeController extends BaseController {


    @Resource
    ISysCheckDisposeService disposeService;




    /**
     * 未处置列表
     */
    @PreAuthorize("@ss.hasPermi('check:dispose:list')")
    @GetMapping("/notList")
    public TableDataInfo noDisposeList(SysCheckDetection detection)
    {
        startPage();
        detection.setCompanyId(getCompanyId());
        List<SysCheckDetection> list = disposeService.selectNotDisposeList(detection);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('check:dispose:operate')")
    @PostMapping("/do")
    public AjaxResult doDispose(@Validated @RequestBody SysCheckDispose dispose){
        if (disposeService.checkAttachList(dispose)){
            return error("处置失败： 附件图片和视频需要至少上传其中一项");
        }
        dispose.setCompanyId(getCompanyId());
        dispose.setReportDisposeNo(dispose.getReportCheckBatchNo());
        return toAjax(disposeService.doDispose(dispose));
    }


    /**
     * 已处置列表
     */
    @PreAuthorize("@ss.hasPermi('check:dispose:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCheckDispose dispose)
    {
        startPage();
        dispose.setCompanyId(getCompanyId());
        List<SysCheckDispose> list = disposeService.selectDisposedList(dispose);
        return getDataTable(list);
    }

    /**
     * 获取检测详情
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('check:dispose:query')")
    public AjaxResult getDispose(@PathVariable Long id){
        return success(disposeService.selectDisposeById(id));
    }

}
